import {
  getProductManufactByPage,
  updateProductManufactInfor,
  getBatchPlanByPage,
} from '@/services/product/productManufactInfor';
import React, { useEffect, useState } from 'react';
import dayjs from 'dayjs';
import { message } from 'antd';
import { DatePicker } from 'antd';
import TreeTable from '@/components/TreeTable';
import advancedFormat from 'dayjs/plugin/advancedFormat';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import localeData from 'dayjs/plugin/localeData';
import weekday from 'dayjs/plugin/weekday';
import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear';
import type { ActionType, ProColumns } from '@ant-design/pro-table';
import './product.module.less';

const ProductManufactInfor: React.FC<{}> = () => {
  const [manuInfo, setManuInfo] = useState();
  const [flag, setFlag] = useState<boolean>(true);
  //最新时间
  const [newTime, setNewTime] = useState();
  //保存当行信息
  const [rowInfo, setRowInfo] = useState();
  const [rowKey, setRowKey] = useState();
  //更新时间函数代码
  const handleNeed = () => {
    setFlag(false);
  };
  const getManufactInfo = async () => {
    const result = await getBatchPlanByPage(
      JSON.stringify({
        current: 1,
        filters: [],
        pageSize: 20,
        sorters: [],
      }),
    );
    setManuInfo(result.data.content);
    console.log(result.data.content);
  };

  useEffect(() => {
    getManufactInfo();
  }, []);

  //date更新
  const onChange = (date, dateString, record) => {
    // const selectedDate = date ? dayjs(date).toDate() : null;
    // const id = record.children ? record.batchProductId : record.id;
    // if (record.children) {
    //   rowInfo[dateString] = dayjs(date).format('YYYY-MM-DD');
    // } else {
    //   rowInfo.children.map((item) => {
    //     if (item.id === id) {
    //       item[dateString] = dayjs(date).format('YYYY-MM-DD');
    //     }
    //   });
    // }
    // setNewTime(record);
  };

  const columns: ProColumns[] = [
    {
      title: '序号',
      dataIndex: 'index',
      valueType: 'index',
      width: 80,
    },
    {
      title: '项目名称', //表头显示的名称
      dataIndex: 'projectName', // 列数据在数据项中对应的路径，支持通过数组查询嵌套路径
    },

    {
      title: '项目编号', //表头显示的名称
      dataIndex: 'projectCode', // 列数据在数据项中对应的路径，支持通过数组查询嵌套路径
    },
    {
      title: '批次交货日期', //表头显示的名称
      dataIndex: 'batchDeliveryDate',
    },
    {
      title: '批次编号', //表头显示的名称
      search: false,
      dataIndex: 'batchPlanCode',
    },
    {
      title: '柜体编号', //表头显示的名称
      search: false,
      dataIndex: 'batchProductCode',
    },
    {
      title: '批次编号', //表头显示的名称
      search: false,
      dataIndex: 'batchPlanCode',
    },

    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      fixed: 'right',
      render: (text, record, _, action) => [
        <a key="editKey" onClick={() => {}}>
          自动排程
        </a>,
      ],
    },
  ];

  return (
    <div className="containner-productmanvfactinfor">
      <TreeTable
        border
        style={{ margin: 40 }}
        data={manuInfo == undefined ? '' : manuInfo}
        columns={columns}
      />
    </div>
  );
};

export default ProductManufactInfor;
